<template>
  <div class="DecRoot">
    <el-card class="box-card">
      <div class="headerBox">
        <div class="leftBox">属性详情</div>
        <div>
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="dialogVisible = true"
            plain
            >绑定属性</el-button
          >
          <el-button @click="$router.back()" plain>返回</el-button>
        </div>
      </div>
    </el-card>
    <el-card class="box-card newCard">
      <el-table
        :data="tableData"
        style="width: 100%; margin-bottom: 20px"
        row-key="id"
        height="66vh"
        header-cell-class-name="tableHeader"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column prop="name" label="属性名称" width="150">
        </el-table-column>
        <el-table-column prop="name" label="是否必选" width="150">
          <template slot-scope="scope">
            {{ scope.row.flag ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column
          prop="inputList"
          label="可选值"
        >
        
        </el-table-column>
        <!-- <el-table-column prop="address" label="操作" width="150">
          <template slot-scope="scope">
            <el-popconfirm
              title="确定要删除该条分类吗？"
              @confirm="deleteCategory(scope.row)"
            >
              <template slot="reference">
                <i
                  class="el-icon-delete"
                  style="font-size: 25px; color: #409eff; cursor: pointer"
                ></i>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column> -->
      </el-table>
    </el-card>

    <el-dialog :visible.sync="dialogVisible" width="50%" class="newDialog">
      <div class="DiaLogHeader">
        <div class="titlebOX">新增</div>
        <div class="chahao" @click="dialogVisible = false">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <el-divider></el-divider>
      <div style="padding: 20px 40px">
        <el-table
          :data="tableDataB"
          style="width: 100%; margin-bottom: 20px"
          row-key="id"
          height="60vh"
          header-cell-class-name="tableHeader"
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        >
          <el-table-column
            prop="pmsProductAttribute.name"
            label="属性名称"
            width="150"
          >
          </el-table-column>
          <el-table-column prop="name" label="是否必选" width="150">
            <template slot-scope="scope">
              {{ scope.row.pmsProductAttribute.flag ? "是" : "否" }}
            </template>
          </el-table-column>
          <el-table-column
            prop="pmsProductAttribute.inputList"
            label="可选值"
          >
          </el-table-column>
          <el-table-column prop="address" label="操作" width="150">
            <template slot-scope="scope">
              <i
                @click="scope.row.flag = !scope.row.flag"
                :class="scope.row.flag ? 'newLan' : ''"
                class="el-icon-circle-check"
                style="font-size: 26px; cursor: pointer"
              ></i>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="btnBox">
        <el-button type="primary" @click="bindingCategoryAndAttribute">
          提交</el-button
        >
        <el-button @click="dialogVisible = false"> 取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  selectAttributeByCategoryId,
  selectAllCategoryByCategoryId,
  bindingCategoryAndAttribute,
} from "@/api/categoryManage.js";
export default {
  data() {
    return {
      form: {
        name: "",
        level: 0,
        inputList: "",
        flag: true,
        chooseMaxNum: true,
      },
      value: true,
      activeName: "first",
      dialogVisible: false,
      tableData: [],
      total: 0,
      ipageCofig: {
        keyWord: "",
        pageNumber: 1,
        pageSize: 10,
      },
      editShow: false,
      newForm: {},
      tableDataB: [],
    };
  },
  created() {
    this.getList();
    this.selectAllCategoryByCategoryId();
  },
  methods: {
    //绑定属性
    bindingCategoryAndAttribute() {
      let arr = [];
      this.tableDataB.forEach((item) => {
        if (item.flag) {
          arr.push(item.pmsProductAttribute.id);
        }
      });
      bindingCategoryAndAttribute({
        categoryId: this.$route.query.id,
        attributeId: arr.join(","),
      }).then((data) => {
        if (data.code == 200) {
          this.$message({
            message: "配置成功",
            type: "success",
          });
          this.dialogVisible = false;
          this.getList();
          this.selectAllCategoryByCategoryId();
        }
      });
    },
    //获取类目下的所有属性
    selectAllCategoryByCategoryId() {
      selectAllCategoryByCategoryId({
        categoryId: this.$route.query.id,
      }).then((data) => {
        this.tableDataB = data.data;
      });
    },
    getList() {
      selectAttributeByCategoryId({
        categoryId: this.$route.query.id,
      }).then((data) => {
        this.tableData = data.data;
      });
    },
  },
  watch: {
    dialogVisible() {
      if (!this.dialogVisible) {
        this.form = {
          name: "",
          level: 0,
          inputList: "",
          flag: true,
          chooseMaxNum: true,
        };
        this.editShow = false;
      }
    },
  },
};
</script>
  <style scoped lang="scss">
.newLan {
  color: rgb(64, 158, 255);
}
/deep/ .el-tabs__nav-scroll {
  display: none;
}
.btnBox {
  display: flex;
  justify-content: center;
  background: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 10px 0;

  .btnImg {
    width: 14px;
    height: 14px;
    vertical-align: middle;
  }
}

.DecRoot {
  padding: 20px;
  padding-left: 5px;
  padding-bottom: 0;

  .newCard {
    height: 75vh;
    margin-top: 20px;
  }

  /deep/ .el-button {
    padding: 9px 15px;
  }

  .el-card {
    .headerBox {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .leftBox {
        display: flex;
        align-items: center;
        font-size: 18px;
        font-weight: 700;

        /deep/ .el-form-item {
          margin-bottom: 0;
        }

        /deep/ .el-input--suffix {
          width: 200px;
        }
      }
    }

    /deep/ .tableHeader {
      background: #edf3ff;
      font-weight: 700;
      color: #666666;
    }

    .iconImg {
      width: 20px;
      height: 20px;
      cursor: pointer;
      margin-right: 10px;
    }

    .pagination {
      display: flex;
      justify-content: space-between;
      margin-top: 10px;

      /deep/ .el-pagination__editor.el-input .el-input__inner {
        height: 28px !important;
      }

      /deep/ .el-input--mini .el-input__inner {
        height: 28px !important;
      }
    }
  }
}
</style>
    <style scoped lang="scss">
.search {
  display: flex;
}
.newDialog {
  /deep/ .el-divider {
    margin: 0px;
  }
  /deep/ .el-dialog__header {
    padding: 0;
  }
  /deep/ .el-form-item__content {
    width: 75%;
  }
  /deep/ .el-select {
    width: 100%;
  }
  /deep/ .tableHeader {
    background: #edf3ff;
    font-weight: 700;
    color: #666666;
    padding: 5px 0;
  }
  .btnBox {
    display: flex;
    justify-content: center;
    background: #fff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 10px 0;
    .btnImg {
      width: 14px;
      height: 14px;
      vertical-align: middle;
    }
    /deep/ .el-button {
      padding: 10px 20px;
    }
  }
  .DiaLogHeader {
    display: flex;
    padding: 10px 20px;
    justify-content: space-between;
    .titlebOX {
      font-size: 16px;
      font-weight: 700;
    }
    .chahao {
      width: 20px;
      height: 20px;
      background-image: url("@/assets/image/icon/chahao.png");
      background-size: 100% 100%;
      text-align: center;
      line-height: 20px;
      color: #e65f00;
      cursor: pointer;
    }
  }
  /deep/ .el-input {
    width: 100% !important;
  }
}
/deep/ .el-dialog__header {
  font-weight: 700;
}
/deep/ .demo-ruleForm {
  padding: 10px;
}

/deep/ .el-form-item {
  margin-bottom: 8px;
}
/deep/ .el-form-item__error {
  z-index: 99;
}
/deep/ .el-dialog__body {
  padding: 0;
  padding-top: 10px;
  padding-bottom: 60px;
}
.dialogTextBox {
  font-size: 14px;
  color: #000000;
}
</style>
  